//
//  DetailPresentationController.swift
//  Chihiro
//
//  Created by point on 2016/12/28.
//  Copyright © 2016年 chihiro. All rights reserved.
//

import UIKit

class DetailPresentationController: UIPresentationController {
    var presntFrame:CGRect = CGRect.zero
    fileprivate lazy var coverView : UIView = UIView()
    
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        presentedView?.frame = presntFrame
        setupCoverView()
    }
    
}
extension DetailPresentationController {
    fileprivate func setupCoverView() {
        containerView?.insertSubview(coverView, at: 0)
        coverView.backgroundColor = UIColor.black.withAlphaComponent(0.5)
        coverView.frame = containerView!.bounds
        let tapGus = UITapGestureRecognizer(target: self, action:#selector(tap(tapGus:)))
        coverView.addGestureRecognizer(tapGus)
    }
    
    @objc fileprivate func tap(tapGus:UITapGestureRecognizer) {
        presentedViewController.dismiss(animated: true, completion: nil)
    }
}
